package com.smh.a04SetDemo1;

import java.util.Iterator;
import java.util.TreeSet;

public class TreeSetDemo {
    public static void main(String[] args) {
        //不重复,无索引,可排序
        //默认从小大大排序
        //基于红黑树实现

        TreeSet<Integer> treeSet = new TreeSet<>();
        treeSet.add(1);
        treeSet.add(3);
        treeSet.add(5);
        treeSet.add(2);
        treeSet.add(4);
        System.out.println(treeSet);

        Iterator<Integer> it = treeSet.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }

        System.out.println("-------------------");
        for (Integer i : treeSet) {
            System.out.println(i);
        }
        System.out.println("-------------------");
        //底层就是增强for
        treeSet.forEach(i->{
            System.out.println(i);
        });






    }
}
